
export default {
    //context指向$store
    addCarts(context, playload) {//playload===product
        return new Promise((resolve, reject) => {
            let oldProduct = null;//旧产品计数
            for (let item of context.state.cartList) {
                if (item.iid === playload.iid) {
                    oldProduct = item;
                }

            }
            //判断oldProuduct
            if (oldProduct) {  //商品数量+1
                // oldProduct.count += 1;
                context.commit('addCounter', oldProduct)
                resolve('添加至购物车')
            }
            else {//添加新的商品
                playload.count = 1;
                context.commit('addToCart', playload)
                resolve('添加至购物车')
            }
        })
    }
}